﻿using Abp.AutoMapper;
using Abp.Linq.Extensions;
using Microsoft.EntityFrameworkCore;
using NetCore.Dtos;
using NetCore.Entities.Organizations;
using NetCore.Interfaces;
using NetCore.Organizations.Dtos;
using NetCore.Services;
using NetCore.Users.Dto;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace NetCore.Organizations
{
    /// <summary>
    /// 机构/岗位 用户
    /// </summary>
    [Description("机构/岗位用户")]
    public class OrganizationUserAppService : BaseNetCoreAppService<OrganizationUser>, IOrganizationUserAppService
    {
        //private readonly IProjectAppService _projectAppService;
        //private readonly INetCoreRepository<Project> _projectRepository;
        public OrganizationUserAppService(
            INetCoreRepository<OrganizationUser> baseRepository) : base(baseRepository)
        {
            //_projectAppService = projectService;
        }

        public async Task<List<OrganizationUserDto>> GetOrganizationUsers(InputIdNullDto input)
        {
            var result = await BaseRepository.GetAll()
                .WhereIf(input.Id.HasValue, m => m.OrganizationId == input.Id)
                .Select(m => new OrganizationUserDto
                {
                    Id = m.Id,
                    UserId = m.UserId,
                    Name = m.Organization.Name,
                    OrganizationId = m.Organization.Id,
                    OrganizationName = m.Organization.Name,
                    User = m.User.MapTo<UserDto>()
                }).ToListAsync();
            return result;
        }
    }
}
